package com.ce.tag;

import java.util.ArrayList;
import java.util.List;

import com.ce.framework.util.StringUtil;
import com.ce.sys.login.model.User;
import com.ce.sys.org.dao.po.SysVOrg;
import com.ce.util.OrgUtil;
import com.ce.util.TreeNode;

public class OrgSelectTag extends AbstractSelectTag {
	private static final long serialVersionUID = 1L;
	
	/** 父机构ID */
	private String parOrg;
	
	/** 是否包含父机构 */
	private boolean hasPar;
	
	/** 机构类型 0所有，1只包括生产机构，2只包括部门 */
	private int orgType;

	@SuppressWarnings("unchecked")
	@Override
	List<TreeNode> getContentList() {
		List<TreeNode> res = new ArrayList<TreeNode>();
		if(StringUtil.isBlank(parOrg)){
			parOrg = User.getUserOrgId();
		}
		if(hasPar){
			res.add(new TreeNode(parOrg,OrgUtil.getOrgName(parOrg)));
		}
		List<SysVOrg> list = null;
		if(orgType==1){
			list = OrgUtil.getChildPro(parOrg);
		}
		else if(orgType==2){
			list = (List<SysVOrg>) OrgUtil.getChildDep(parOrg);
		}
		else{
			list = OrgUtil.getChildOrg(parOrg);
		}
		if(list==null){
			return res;
		}
		for(SysVOrg org:list){
			res.add(new TreeNode(org.getVcId(),org.getVcName()));
		}
		return res;
	}

	public void setHasPar(boolean hasPar) {
		this.hasPar = hasPar;
	}

	public void setOrgType(int orgType) {
		this.orgType = orgType;
	}

	public void setParOrg(String parOrg) {
		this.parOrg = parOrg;
	}

}
